<template>
  <div class="authentication_cover">
    <!-- <h2 class="nav_title">教师审核</h2> -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-image
            style="width: 100px; height: 100px"
            :src="`${$store.state.baseurl}${props.row.img_url}`"
            :preview-src-list="props.row.srcList"
          >
          </el-image>
          <!-- <img class="img1" :src="`${$store.state.baseurl}${props.row.img_url}`" alt=""> -->
        </template>
      </el-table-column>
      <el-table-column type="index"> </el-table-column>
      <el-table-column label="提交时间" prop="time"> </el-table-column>
      <el-table-column label="用户呢称" prop="username"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">通过</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import moment from "moment";
import { getAllMidels, putPass,putNoPass } from "@/api/data";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  mounted() {
    this.getall()


  },
  methods: {
    // 通过了教师审核
    async handleEdit(row) {
  
      let data = await putPass({
        user_id: row.middle_id._id,
        middle_id: row._id,
        admin_id:this.$store.state.userdata._id
      });

      if(data.code==200){
        this.$message.success(data.msg)
        this.getall()
      }else{
        this.$message.error(data.msg)
      }
    },

    async handleDelete(row) {
      // console.log(row);
      let data=await putNoPass({middle_id:row._id})
      this.$message.success(data.msg)
    },

    // 获取所有的需要审核的信息
    async getall() {
      let data = await getAllMidels({ _id: this.$store.state.userdata._id });
      // console.log(data);
      if (data.code == 200) {
        data.data.forEach((item, index) => {
          data.data[index].username = item.middle_id.username;
          data.data[index].srcList = [];
          data.data[index].srcList.push(
            `${this.$store.state.baseurl}${item.img_url}`
          );
          // 格式化时间
          item.time = moment(item.time).format("YYYY-MM-DD HH:mm:ss");
        });
        // console.log(data.data)
        this.tableData = data.data;
      } else {
        this.$message.error(data.msg);
      }
    },
  },
};
</script>

<style>
.authentication_cover {
  padding: 20px;
}
.nav_title {
  height: 60px;
  line-height: 60px;
  color: #444;
  text-align: center;
  margin-bottom: 20px;
}
.img1 {
  height: 200px;
}
</style>